export const filterPrice = price => price.toFixed(2);

export const filterTel = tel => tel.slice(0, 3) + "****" + tel.slice(7);

// 时间过滤 时间戳转时间
export const fliterTime = (t) => {
    t = Number(t);
    if (t == null) {
        return null;
    }
    let date = new Date(t);
    let y = 1900 + date.getYear();
    let m = "0" + (date.getMonth() + 1);
    let d = "0" + date.getDate();
    return y + "." + m.substring(m.length - 2, m.length) + "." + d.substring(d.length - 2, d.length);
}

export const countTime = (t) => {
    //当前时间
    var now = new Date().getTime();
    //结束时间
    var endTime = new Date(t).getTime();

    //时间差
    var ctime = endTime - now;

    if (ctime >= 0) {
        var d = Math.floor(ctime / 1000 / 3600 / 24); //天数
        var h = Math.floor(ctime / 1000 / 60 / 60 % 24) + d * 24;
        h = h < 10 ? "0" + h : h;
        var m = Math.floor(ctime / 1000 / 60 % 60);
        m = m < 10 ? "0" + m : m;
        var s = Math.floor(ctime / 1000 % 60);
        s = s < 10 ? "0" + s : s;
    } else {
        return 0;
    }
    return { h, m, s, d }
}